import json

from home.models import *

def common_hottages_news(request):
    #热门标签
    hot_tags = Article.objects.values('tags').order_by('-total_views').distinct()[:9]
    #最新文章
    news_artcle = Article.objects.order_by('-create_time')[0:2]


    #获取博客分类的全部信息
    categories = ArticleCategory.objects.all()
    #读取cookie中的用户信息
    if 'login_name' in request.COOKIES:
        username = request.COOKIES.get('login_name')
        username = json.loads(username)
    # 如果没有读取到则给个空值
    else:
        username=''
    return {"hot_tags":hot_tags,'news_artcle':news_artcle,'categories':categories,'username':username}